package it.csi.finregio.finreges.junit.util.parser;

import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
import javax.swing.text.rtf.RTFEditorKit;

import org.apache.commons.io.IOUtils;

import junit.framework.TestCase;

public class HTMLtoRTFTest extends TestCase {

	public void testConvert() throws Exception {
		// HTMLtoRTF.convert(new FileOutputStream("c:/html2rtf.rtf"), new
		// InputStreamReader(HTMLtoRTFTest.class
		// .getResourceAsStream("/it/csi/finregio/finreges/junit/presentation/parser/Anteprima.htm"))
		// );
//		HTMLtoRTF
//				.convert(
//						new FileOutputStream("c:/dddddd.rtf"),
//						new InputStreamReader(
//								new FileInputStream(
//										"C:\\progetti\\workspace\\finregio\\src\\web\\finreges\\jsp\\stampaTMP.html")));
//		InputStream in = new FileInputStream("c:\\thread.jspa.htm");
		InputStream in = new FileInputStream("C:\\progetti\\workspace\\finregio\\src\\web\\finreges\\jsp\\stampaTMP.html");
//		DefaultStyledDocument tempHTMLDoc = new DefaultStyledDocument();
		StyleSheet style = new StyleSheet();
		HTMLDocument tempHTMLDoc = new HTMLDocument();
		HTMLEditorKit htmlKit = new HTMLEditorKit();
		InputStreamReader reader = new InputStreamReader(in);
//		tempHTMLDoc.remove(0, tempHTMLDoc.getLength());
		htmlKit.read(reader, tempHTMLDoc, 0);
		FileOutputStream fout = new FileOutputStream("c:\\"+this.getClass().getName()+".rtf");
		
		RTFEditorKit rtfKit = new RTFEditorKit();
		rtfKit.write(fout, tempHTMLDoc, 0, tempHTMLDoc
				.getLength());

	}

}
